(function(){
    app.controller('videosCtrl', ['$rootScope','$scope', 'RESTService', function($rootScope, $scope, RESTService){
        $rootScope.selecInd = 4;
        $rootScope.showTabs = true;
        $scope.$on('$destroy',function(){
            $rootScope.showTabs = false;
        });

        $scope.videos = {
            0:{
                'heading': 'ReviewFollowed',
                'headText': '已关注分析',
                'data': {}
            },
            1:{
                'heading': 'ReviewAll',
                'headText': '全部分析',
                'data': {}
            },
            2:{
                'heading': 'Learn',
                'headText': '学习',
                'data': {}
            }
        };


        $scope.getVideos = function(type, ind){
            RESTService.getResponse('/rest/video/getVideos?videoType=' + type + '&pageNo=1&pageSize=20&like=').then(
                function(res){
                    $scope.videos[ind].data = res.data;
                }
            );
        };

        // console.log($stateParams);
    }]);

    app.controller('videoPlayCtrl', ['$scope', '$stateParams', 'RESTService', '$sce', function($scope, $stateParams, RESTService, $sce){
        RESTService.getResponse('/rest/video/getVideo?videoId=' + $stateParams.videoId).then(function(res){
            $scope.videoInfo = res.data[0];
            $scope.trustSrc = function(src){
                return $sce.trustAsResourceUrl(src);
            };
            $(function(){
                if($scope.videoInfo.video != null){
                    var playBox = $('iframe#playBox')[0];
                    playBox.style.height = playBox.offsetWidth*0.6 + 'px';
                    console.dir($('div#playBox')[0]);
                }
            });
        });

    }]);
})();
